package com.alumni_circle.mapper.home;

import com.alumni_circle.entity.home.ClubActivity;
import com.alumni_circle.entity.home.VO.ClubActivityViewVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 龙小虬
 * @since 2020-07-06 22:12
 */
public interface ClubActivityMapper extends BaseMapper<ClubActivity> {

    @Select("SELECT club_activity.title,club_activity.content,club_activity.praise,club_activity.create_time,club_activity.views,club_activity.club_name,club_activity.picture,user.`name`,user.`icon`\n" +
            "FROM user_club,user,club_activity\n" +
            "WHERE user.id = user_club.user_id and club_activity.state = '0' and user_club.club_activity_id = club_activity.id\n" +
            "ORDER BY create_time DESC")
    List<ClubActivityViewVO> selectListClubActivity();

    @Select("SELECT club_activity.title,club_activity.id,club_activity.content,club_activity.praise,club_activity.create_time,club_activity.views,club_activity.club_name,club_activity.picture,user.`name`,user.`icon`\n" +
            "FROM user_club,user,club_activity\n" +
            "WHERE user.id = user_club.user_id and club_activity.state = '0' and user_club.club_activity_id = club_activity.id and user.id = #{id}\n" +
            "ORDER BY create_time DESC")
    List<ClubActivityViewVO> selectMyListClubActivity(@Param("id") String id);

    @Select("SELECT club_activity.title,club_activity.id,club_activity.content,club_activity.praise,club_activity.create_time,club_activity.views,club_activity.club_name,club_activity.picture,user.`name`,user.`icon`\n" +
            "FROM user_club,user,club_activity\n" +
            "WHERE user.id = user_club.user_id and club_activity.state = '0' and user_club.club_activity_id = club_activity.id and user.id = #{id}\n" +
            "and (club_activity.title like concat ('%',#{search},'%') or club_activity.content like concat('%',#{search},'%'))\n" +
            "ORDER BY create_time DESC")
    List<ClubActivityViewVO> searchMyListClubActivity(@Param("id") String id,@Param("search") String search);

    /**
     * 搜索我的社团发布的内容
     * @param search
     * @return
     */
    @Select("SELECT club_activity.title,club_activity.content,club_activity.id,club_activity.time,club_activity.place,club_activity.praise,club_activity.create_time,club_activity.views,club_activity.club_name,club_activity.picture,user.`name`,user.`icon`\n" +
            "            FROM user_club,user,club_activity\n" +
            "            WHERE user.club= #{club} and user.id = user_club.user_id and club_activity.state = '0' and user_club.club_activity_id = club_activity.id and user.club = club_activity.club_name and (club_activity.title like concat ('%',#{search},'%') or club_activity.content like concat('%',#{search},'%'))\n" +
            "            ORDER BY create_time DESC")
    List<ClubActivityViewVO> searchClubActivity(@Param("club") String club, @Param("search") String search);
}
